package activity

import (
	"activity_srv/activityclient"
	"api/internal/svc"
	"api/internal/types"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateSeckillGoodsLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateSeckillGoodsLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateSeckillGoodsLogic {
	return &CreateSeckillGoodsLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateSeckillGoodsLogic) CreateSeckillGoods(req *types.CreateSeckillGoodsRequest) (resp *types.Response, err error) {
	good, err := l.svcCtx.ActivityRpc.CreateSeckillGood(l.ctx, &activityclient.CreateSeckillGoodRequest{
		GoodskuId:  int64(req.GoodSkuId),
		StockCount: int64(req.StockCount),
		StartTime:  req.StartTime,
		EndTime:    req.EndTime,
		Price:      float32(req.Price),
	})
	if err != nil {
		return &types.Response{
			Code:    400,
			Message: err.Error(),
			Data:    nil,
		}, nil
	}
	return &types.Response{
		Code:    200,
		Message: "success",
		Data:    good.SeckillGoodId,
	}, nil
}
